<template>
  <div class="refine_sosOrganization" :style="{'height':fheight}">
    <h2 class="titleblue">搜救机构</h2>
    <div class="contant">
      <el-row>
        <el-col :span="24">
          <div class="grid-content">
            <div class="create" @click="add" v-if="sysShow">新增机构</div>
          </div>

<!--          <div class="grid-content">-->
<!--            <div class="create" style="padding: 0 20px;" @click="showYanTai">烟台市海上搜救中心</div>-->
<!--          </div>-->
        </el-col>
      </el-row>
      <div class="main">
        <div class="orgbtn fl"><label class="create bgblue" style="padding: 0 20px;" @click="showYanTai">烟台市海上搜救中心</label><em></em></div>
<!--        <div class="orgbtn fl"><label class="create bgblue" @click="showYanTai">烟台市海上搜救中心</label><em></em></div>-->
        <div class="listItem">
          <ul>
            <li :class="index==level1?'activeli':''" v-for="(item,index) in sos" class="itemli">
              <hr></hr>
              <div class="itemson" @click='actived(index, "level1")'>
                <em :class="index==level1||!item.subset?'el-icon-minus':'el-icon-plus'"
                    style="cursor: pointer;"></em>
                <span :class="index==level1?'active':''" style="cursor: pointer;">{{item.name}}</span></div>
              <!-- <i class="el-icon-edit edit-icon" @click="editbtn(item.d_id)" style="position:relative;z-index:3;cursor: pointer;margin-left:10px;"></i> -->
              <hr v-if="index==level1" style="width:200px"></hr>
              <div class="items" ref="ele">
                <ul v-if='index==level1'>
                  <li v-for="(item1,index1) in item.subset" class="itemlison">
                    <hr></hr>
                    <div class="itemson" @click='actived(index1, "level2")'>
                      <em :class="index1==level2||!item1.subset?'el-icon-minus':'el-icon-plus'"
                          style="cursor: pointer;"></em>
                      <span id="ul1" style="cursor: pointer;" :class="index1==level2?'active':''">{{item1.name}}</span>
                    </div>
                    <i class="el-icon-edit edit-icon" @click="editbtn(item1)"
                       style="position:relative;z-index:3;cursor: pointer;margin-left:10px;"></i>
                    <hr style="width:215px" v-if="index1==level2&&item1.subset"></hr>
                    <div class="items-cont" id="ul2">
                      <ul v-if='index1==level2'>
                        <li v-for='(item2,index2) in item1.subset'
                            :class='index2==item1.subset.length-1&&item2.oneph3?"margin50":"margin25"'>
                          <div class="item-title">
                            <hr></hr>
                            <em class="el-icon-minus"></em><span class="active">{{item2.name}}</span>
                            <i class="el-icon-edit" @click="editbtn(item2)"
                               style="position:relative;z-index:3;cursor: pointer;margin-left:10px;"></i>
                          </div>
                          <div class="item-phone active" v-if="item2.oneph1">
                            <i class="el-icon-phone-outline"></i>
                            {{item2.oneph1}}
                          </div>
                          <div class="item-phone active" v-if="item2.oneph2">
                            <i class="el-icon-phone-outline"></i>
                            {{item2.oneph2}}
                          </div>
                          <div class="item-phone active" v-if="item2.oneph3">
                            <i class="el-icon-phone-outline"></i>
                            {{item2.oneph3}}
                          </div>
                        </li>
                      </ul>
                    </div>
                  </li>
                </ul>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <el-dialog title="" :visible.sync="adddialog" width="80%" append-to-body @close="close" @open='asdShow=true'>
      <span>
        <router-view @close="close" :detail="detail" :id="ddid" v-if="asdShow"></router-view>
      </span>
    </el-dialog>
    <!-- 烟台 -->
    <el-dialog title="" :visible.sync="yantaiDialog" width="80%" append-to-body @close="close">
      <div  class="refine_sosOrganization" style="height: 710px; padding-top: 60px;">
        <div class="main">
          <div class="orgbtn fl" style="left: 30px"><label class="create bgblue" style="padding: 0 20px;">烟台市海上搜救中心</label><em></em></div>
          <div class="listItem" style="margin-left: 180px;">
            <ul style="border-left: none;transform: translateY(3px)">
              <li :class="index==level1?'activeli':''" v-for="(item,index) in sosT" class="itemli">
                <hr></hr>
                <div class="itemson" @click='actived(index, "level1")'>
                  <em :class="index==level1||!item.subset?'el-icon-minus':'el-icon-plus'"
                      style="cursor: pointer;"></em>
                  <span :class="index==level1?'active':''" style="cursor: pointer;">{{item.name}}</span></div>
                <!-- <i class="el-icon-edit edit-icon" @click="editbtn(item.d_id)" style="position:relative;z-index:3;cursor: pointer;margin-left:10px;"></i> -->
                <hr v-if="index==level1" style="width:200px"></hr>
                <div class="items" ref="ele">
                  <ul v-if='index==level1'>
                    <li v-for="(item1,index1) in item.subset" class="itemlison">
                      <hr></hr>
                      <div class="itemson" @click='actived(index1, "level2")'>
<!--                        <em :class="index1==level2||!item1.subset?'el-icon-minus':'el-icon-plus'"-->
                        <em class="el-icon-minus"
                            style="cursor: pointer;"></em>
                        <span id="ul1" style="cursor: pointer;" :class="index1==level2?'active':''">{{item1.name}}</span>
                      </div>
                      <i class="el-icon-edit edit-icon" @click="editbtn(item1)"
                         style="position:relative;z-index:3;cursor: pointer;margin-left:10px;"></i>
                    </li>
                  </ul>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import sosOrgService from '@/services/SosOrgService'

  export default {
    name: 'SosOrganization',
    data: function () {
      return {
        adddialog: false,
        sos: [],
        sosT: [],
        sosAll: [],
        level1: -1,
        level2: -1,
        fheight: '1150px',
        distance: '',
        sysShow: true,
        ddid: '',
        asdShow: true,
        detail: '',
        yantaiDialog: false
      }
    },
    created () {
      this.getData(0)
    },
    methods: {
      showYanTai () {
          this.yantaiDialog = true
      },
      actived (index, key) {
          if (this[key] == index) {
              this[key] = -1
              return false
          }
          this[key] = index
        // this.fheight= this.$refs.ele[index].clientHeight+'px'
      },
      add () {
        var that = this
        this.adddialog = true
        this.$router.push({name: 'CreateSos', params: {sos: that.sosAll}})
        this.ddid = ''
        this.detail = 'create'
      },
      getData (num) {
        sosOrgService.searchTree('').then(res => {
          this.sosAll = res
          this.sos = res.filter(fil => {
              return fil.name != '烟台市海上搜救中心'
          })
          this.sosT = res.filter(fin => {
              return fin.name == '烟台市海上搜救中心'
          })
          // this.dpOption = res
        })
      },
      close () {
        this.adddialog = false
        this.getData()
        this.asdShow = false
        this.$router.push('/sos-organization')
      },
      editbtn (val) {
        var that = this
        this.adddialog = true
        this.$router.push({name: 'CreateSos', params: {data: val, sos: that.sosAll}})
        this.ddid = val.id
        this.detail = 'edit'
      }
    }
  }
</script>

<style scoped lang="scss">
  .refine_sosOrganization {
    width: 100%;
    display: inline-block;
    padding-bottom: 50px;
    min-height: 500px;

    .main {
      width: 100%;
      display: inline-block;
      position: relative;
      margin-top: 50px;
      padding-left: 50px;
      box-sizing: border-box;
    }

    .orgbtn {
      position: absolute;
      left: 10px;
      top: 50%;
      margin-top: -24px;
    }

    .orgbtn em {
      height: 1px;
      width: 30px;
      background: #aaa;
      margin-top: 19px;
      float: left;
      margin-left: -10px;
    }

    .orgbtn .bgblue {
      background: rgb(41, 139, 245)
    }

    .edit-icon {
      float: left;
      margin-top: 5px;
    }

    .listItem {
      margin-left: 160px;
      position: relative;
    }

    .listItem ul {
      border-left: 1px solid #aaa;
    }

    .activeli {
      position: relative;
      z-index: 99;
    }

    .listItem li em {
      padding: 0px;
      font-size: 12px;
      margin-right: 10px;
      border: 1px solid #aaa;
      color: #333;
      float: left;
      margin-top: 6px;
    }

    .listItem li {
      margin-bottom: 10px;
    }

    .listItem li:first-child {
      transform: translateY(-50%) !important;
      margin-bottom: 0px !important;
      margin-top: 0 !important;
    }

    .listItem li:last-child {
      transform: translateY(46%);
      margin-top: -10px;
    }

    .listItem li:after {
      content: '';
      display: block;
      clear: both;
    }

    .listItem li hr {

      width: 30px;
      transform: translateY(-150%);
      margin-left: -1px;
      margin-top: 15px;
      float: left;
    }

    .listItem li span {
      float: left;
    }

    .listItem li .active {
      color: rgb(41, 139, 245);
    }

    .listItem li.active em {
      color: #ccc;
    }

    .itemson span {
      position: relative;
      /*z-index: 9999;*/
    }

    .itemson {
      float: left;
    }

    .items:after {
      content: '';
      display: block;
      clear: both;
    }

    .items {
      position: absolute;
      float: left;
      margin-top: 6px;
      left: 258px;
      top: -50px;
      background: #fff;
      z-index: 99;
      padding-top: 10px;
    }

    .items li {
      position: relative;
      z-index: 99;
    }

    .items-cont {
      position: absolute;
      left: 314px;
      top: 0px;
      background: #fff;
      width: 300px;
      margin-left: -2px;
    }

    .items-cont li:first-child {
      transform: translateY(0%) !important;
      margin-bottom: 0px !important;
      top: -14px !important;
      position: relative;
      width: 300px;
    }

    .items-cont .margin50 {
      transform: translateY(0%) !important;
      margin-top: 0px !important;
      height: 13px;
    }

    .items-cont .margin50:first-child {
      height: 13px;
    }

    .items-cont .margin25:last-child {
      transform: translateY(0%);
      margin-top: 0px;
      top: 0;
      height: 12px;
    }

    .item-phone {
      position: relative;
      left: 55px;
    }

    .el-icon-phone-outline {
      margin-right: 5px;
    }

    .item-title {
      width: 100%;
      float: left;
    }
  }

</style>
